using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class MyData : MonoBehaviour
{
    public List<System.Reflection.FieldInfo> fields;
    public object GetValue(string fieldName)
    {
        foreach (var field in fields)
        {
            if(field.Name == fieldName)
            {
                return field.GetValue(this);
            }
        }
        return null;
    }
    public void SetValue(string fieldName, object value)
    {
        foreach (var field in fields)
        {
            if (field.Name == fieldName)
            {
                field.SetValue(this, value);
                return ;
            }
        }
    }
    private static List<string> FatherFieldsName=null;
    protected void Awake()
    {
        if (FatherFieldsName == null)
        {
            FatherFieldsName = new List<string>();
            foreach (var info in typeof(MyData).GetFields())
            {
                FatherFieldsName.Add(info.Name);
            }
        }
        fields = new();
        foreach (var info in this.GetType().GetFields())
        {
            
            if(FatherFieldsName.IndexOf(info.Name)==-1)
            {
                fields.Add(info);
                
            }
            
        }
    }
    private void Start()
    {
        foreach(var member in this.fields)
        {
            Debug.Log(member.Name);
            
            
        }
    }
}
